package cn.one.service.user;



import cn.one.common.Constants;
import cn.one.common.EmptyUtils;
import cn.one.common.Page;
import cn.one.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private cn.one.dao.user.UserMapper UserMapper;

    public User getUserById(Integer w_number)throws Exception{
        return UserMapper.getUserById(w_number);
    }

    public List<User>	getUserListByMap(Map<String,Object> param)throws Exception{
        return UserMapper.getUserListByMap(param);
    }

    public Integer getUserCountByMap(Map<String,Object> param)throws Exception{
        return UserMapper.getUserCountByMap(param);
    }

    public Integer AddUser(User User)throws Exception{
            User.setCreationDate(new Date());
            return UserMapper.insertUser(User);
    }

    public Integer ModifyUser(User User)throws Exception{
        User.setModifyDate(new Date());
        return UserMapper.updateUser(User);
    }

    public Integer DeleteUserById(Integer w_number)throws Exception{
        return UserMapper.deleteUserById(w_number);
    }

    public Page<User> queryUserPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize)throws Exception{
        Integer total = UserMapper.getUserCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<User> UserList = UserMapper.getUserListByMap(param);
        page.setRows(UserList);
        return page;
    }

}
